package com.atguigu.gulimall.search.controller;

import com.atguigu.gulimall.search.service.MallSearchService;
import com.atguigu.gulimall.search.vo.SearchParamVo;
import com.atguigu.gulimall.search.vo.SearchResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping(method = {RequestMethod.GET,RequestMethod.POST})
public class SearchController {

    @Autowired
    MallSearchService mallSearchService;

    /*
    * 自动将页面提交过来的所有请求参数封装成指定的对象
    * */
    @GetMapping("/list.html")
    public String listPage(SearchParamVo searchParamVo, Model model, HttpServletRequest request){
        searchParamVo.set_queryString(request.getQueryString());
        SearchResultVo result = mallSearchService.search(searchParamVo);



        model.addAttribute("result",result);

        return "list";
    }
}
